Skip to contentSkip to conversation

Change in openvpn[master]: otime: Fix various conversion warnings

Openvpn-devel Superseded flichtenheld (Code Review) 2 participants 6 messages Oct 14, 2025 – Nov 16, 2025 1 message not in the archive

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1760452015000.Ie22f4902162b7004542f030c734b968de71e0e9e@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email

to review the following change.

Change subject: otime: Fix various conversion warnings
......................................................................

otime: Fix various conversion warnings

Generally just use better types. Use typedef
to handle the Win32 situation where tv_sec
is long which is smaller than time_t (which
is long long).

Change-Id Ie22f4902162b7004542f030c734b968de71e0e9e

---
M src/openvpn/otime.c
M src/openvpn/otime.h

2 files changed, 26 insertions(+), 39 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/74/1274/1

src/openvpn/otime.c +7 -20
index d9bf157..1b3b096 100644
@@ -95,50 +95,37 @@
 const char *
 tv_string_abs(const struct timeval *tv, struct gc_arena *gc)
 {
-    return time_string((time_t)tv->tv_sec, (long)tv->tv_usec, true, gc);
+    return time_string(tv->tv_sec, tv->tv_usec, true, gc);
 }
 
 /* format a time_t as ascii, or use current time if 0 */
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 const char *
-time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)
+time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(64, gc);
     struct timeval tv;
 
-    if (t)
-    {
-        tv.tv_sec = t;
-        tv.tv_usec = usec;
-    }
-    else
+    if (!t)
     {
         gettimeofday(&tv, NULL);
+        t = tv.tv_sec;
+        usec = tv.tv_usec;
     }
 
-    t = tv.tv_sec;
     struct tm *tm = localtime(&t);
 
     buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1,
                tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-    if (show_usec && tv.tv_usec)
+    if (show_usec && usec)
     {
-        buf_printf(&out, " us=%ld", (long)tv.tv_usec);
+        buf_printf(&out, " us=%ld", (long)usec);
     }
 
     return BSTR(&out);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Limit the frequency of an event stream.
  *
src/openvpn/otime.h +19 -19
index 108d0f2..60533fd 100644
@@ -27,6 +27,14 @@
 #include "integer.h"
 #include "buffer.h"
 
+#ifdef _WIN32
+typedef long tv_sec_t;
+typedef long tv_usec_t;
+#else
+typedef time_t tv_sec_t;
+typedef suseconds_t tv_usec_t;
+#endif
+
 struct frequency_limit
 {
     int max;
@@ -42,7 +50,7 @@
 bool frequency_limit_event_allowed(struct frequency_limit *f);
 
 /* format a time_t as ascii, or use current time if 0 */
-const char *time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc);
+const char *time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc);
 
 /* struct timeval functions */
 
@@ -59,11 +67,6 @@
 extern time_t now_usec;
 void update_now_usec(struct timeval *tv);
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static inline int
 openvpn_gettimeofday(struct timeval *tv, void *tz)
 {
@@ -71,8 +74,8 @@
     if (!status)
     {
         update_now_usec(tv);
-        tv->tv_sec = now;
-        tv->tv_usec = now_usec;
+        tv->tv_sec = (tv_sec_t)now;
+        tv->tv_usec = (tv_usec_t)now_usec;
     }
     return status;
 }
@@ -116,20 +119,21 @@
 
 /* return tv1 - tv2 in usec, constrained by max_seconds */
 static inline int
-tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const unsigned int max_seconds)
+tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const int max_seconds)
 {
     const int max_usec = max_seconds * 1000000;
-    const int sec_diff = tv1->tv_sec - tv2->tv_sec;
+    const tv_sec_t sec_diff = tv1->tv_sec - tv2->tv_sec;
 
-    if (sec_diff > ((int)max_seconds + 10))
+    if (sec_diff > (max_seconds + 10))
     {
         return max_usec;
     }
-    else if (sec_diff < -((int)max_seconds + 10))
+    else if (sec_diff < -(max_seconds + 10))
     {
         return -max_usec;
     }
-    return constrain_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec, max_usec);
+    const time_t complete_diff = sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec);
+    return constrain_int((int)complete_diff, -max_usec, max_usec);
 }
 
 static inline void
@@ -223,8 +227,8 @@
 static inline void
 tv_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2)
 {
-    int sec = t2->tv_sec - t1->tv_sec;
-    int usec = t2->tv_usec - t1->tv_usec;
+    tv_sec_t sec = t2->tv_sec - t1->tv_sec;
+    tv_usec_t usec = t2->tv_usec - t1->tv_usec;
 
     while (usec < 0)
     {
@@ -241,10 +245,6 @@
     dest->tv_usec = usec;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #define TV_WITHIN_SIGMA_MAX_SEC  600
 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie22f4902162b7004542f030c734b968de71e0e9e
Gerrit-Change-Number: 1274
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email )

Change subject: otime: Fix various conversion warnings
......................................................................

Patch Set 8: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie22f4902162b7004542f030c734b968de71e0e9e
Gerrit-Change-Number: 1274
Gerrit-PatchSet: 8
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 16 Nov 2025 13:57:42 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#3 lore raw

PATCH v8 1/1 otime: Fix various conversion warnings

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Generally just use better types. Use typedef
to handle the Win32 situation where tv_sec
is long which is smaller than time_t (which
is long long).

Change-Id Ie22f4902162b7004542f030c734b968de71e0e9e

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274
This mail reflects revision 8 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/otime.c +7 -20
index d9bf157..1b3b096 100644
@@ -95,50 +95,37 @@
 const char *
 tv_string_abs(const struct timeval *tv, struct gc_arena *gc)
 {
-    return time_string((time_t)tv->tv_sec, (long)tv->tv_usec, true, gc);
+    return time_string(tv->tv_sec, tv->tv_usec, true, gc);
 }
 
 /* format a time_t as ascii, or use current time if 0 */
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 const char *
-time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)
+time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(64, gc);
     struct timeval tv;
 
-    if (t)
-    {
-        tv.tv_sec = t;
-        tv.tv_usec = usec;
-    }
-    else
+    if (!t)
     {
         gettimeofday(&tv, NULL);
+        t = tv.tv_sec;
+        usec = tv.tv_usec;
     }
 
-    t = tv.tv_sec;
     struct tm *tm = localtime(&t);
 
     buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1,
                tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-    if (show_usec && tv.tv_usec)
+    if (show_usec && usec)
     {
-        buf_printf(&out, " us=%ld", (long)tv.tv_usec);
+        buf_printf(&out, " us=%ld", (long)usec);
     }
 
     return BSTR(&out);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Limit the frequency of an event stream.
  *
src/openvpn/otime.h +19 -19
index 108d0f2..60533fd 100644
@@ -27,6 +27,14 @@
 #include "integer.h"
 #include "buffer.h"
 
+#ifdef _WIN32
+typedef long tv_sec_t;
+typedef long tv_usec_t;
+#else
+typedef time_t tv_sec_t;
+typedef suseconds_t tv_usec_t;
+#endif
+
 struct frequency_limit
 {
     int max;
@@ -42,7 +50,7 @@
 bool frequency_limit_event_allowed(struct frequency_limit *f);
 
 /* format a time_t as ascii, or use current time if 0 */
-const char *time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc);
+const char *time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc);
 
 /* struct timeval functions */
 
@@ -59,11 +67,6 @@
 extern time_t now_usec;
 void update_now_usec(struct timeval *tv);
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static inline int
 openvpn_gettimeofday(struct timeval *tv, void *tz)
 {
@@ -71,8 +74,8 @@
     if (!status)
     {
         update_now_usec(tv);
-        tv->tv_sec = now;
-        tv->tv_usec = now_usec;
+        tv->tv_sec = (tv_sec_t)now;
+        tv->tv_usec = (tv_usec_t)now_usec;
     }
     return status;
 }
@@ -116,20 +119,21 @@
 
 /* return tv1 - tv2 in usec, constrained by max_seconds */
 static inline int
-tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const unsigned int max_seconds)
+tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const int max_seconds)
 {
     const int max_usec = max_seconds * 1000000;
-    const int sec_diff = tv1->tv_sec - tv2->tv_sec;
+    const tv_sec_t sec_diff = tv1->tv_sec - tv2->tv_sec;
 
-    if (sec_diff > ((int)max_seconds + 10))
+    if (sec_diff > (max_seconds + 10))
     {
         return max_usec;
     }
-    else if (sec_diff < -((int)max_seconds + 10))
+    else if (sec_diff < -(max_seconds + 10))
     {
         return -max_usec;
     }
-    return constrain_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec, max_usec);
+    const time_t complete_diff = sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec);
+    return constrain_int((int)complete_diff, -max_usec, max_usec);
 }
 
 static inline void
@@ -223,8 +227,8 @@
 static inline void
 tv_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2)
 {
-    int sec = t2->tv_sec - t1->tv_sec;
-    int usec = t2->tv_usec - t1->tv_usec;
+    tv_sec_t sec = t2->tv_sec - t1->tv_sec;
+    tv_usec_t usec = t2->tv_usec - t1->tv_usec;
 
     while (usec < 0)
     {
@@ -241,10 +245,6 @@
     dest->tv_usec = usec;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #define TV_WITHIN_SIGMA_MAX_SEC  600
 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)
 
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: otime: Fix various conversion warnings

Stared-at-code, ran full client/server tests (on FreeBSD), "things related to time differences..." - all passed.

Your patch has been applied to the master branch.

commit f265486bf2175f15b834f191136820d51fd7e278

Author: Frank Lichtenheld
Date:   Sun Nov 16 14:57:52 2025 +0100
     otime: Fix various conversion warnings

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg34462.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#9) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: otime: Fix various conversion warnings
......................................................................

otime: Fix various conversion warnings

Generally just use better types. Use typedef
to handle the Win32 situation where tv_sec
is long which is smaller than time_t (which
is long long).

Change-Id Ie22f4902162b7004542f030c734b968de71e0e9e

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34462.html

---
M src/openvpn/otime.c
M src/openvpn/otime.h

2 files changed, 26 insertions(+), 39 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/74/1274/9

src/openvpn/otime.c +7 -20
index d9bf157..1b3b096 100644
@@ -95,50 +95,37 @@
 const char *
 tv_string_abs(const struct timeval *tv, struct gc_arena *gc)
 {
-    return time_string((time_t)tv->tv_sec, (long)tv->tv_usec, true, gc);
+    return time_string(tv->tv_sec, tv->tv_usec, true, gc);
 }
 
 /* format a time_t as ascii, or use current time if 0 */
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 const char *
-time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)
+time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(64, gc);
     struct timeval tv;
 
-    if (t)
-    {
-        tv.tv_sec = t;
-        tv.tv_usec = usec;
-    }
-    else
+    if (!t)
     {
         gettimeofday(&tv, NULL);
+        t = tv.tv_sec;
+        usec = tv.tv_usec;
     }
 
-    t = tv.tv_sec;
     struct tm *tm = localtime(&t);
 
     buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1,
                tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-    if (show_usec && tv.tv_usec)
+    if (show_usec && usec)
     {
-        buf_printf(&out, " us=%ld", (long)tv.tv_usec);
+        buf_printf(&out, " us=%ld", (long)usec);
     }
 
     return BSTR(&out);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Limit the frequency of an event stream.
  *
src/openvpn/otime.h +19 -19
index 108d0f2..60533fd 100644
@@ -27,6 +27,14 @@
 #include "integer.h"
 #include "buffer.h"
 
+#ifdef _WIN32
+typedef long tv_sec_t;
+typedef long tv_usec_t;
+#else
+typedef time_t tv_sec_t;
+typedef suseconds_t tv_usec_t;
+#endif
+
 struct frequency_limit
 {
     int max;
@@ -42,7 +50,7 @@
 bool frequency_limit_event_allowed(struct frequency_limit *f);
 
 /* format a time_t as ascii, or use current time if 0 */
-const char *time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc);
+const char *time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc);
 
 /* struct timeval functions */
 
@@ -59,11 +67,6 @@
 extern time_t now_usec;
 void update_now_usec(struct timeval *tv);
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static inline int
 openvpn_gettimeofday(struct timeval *tv, void *tz)
 {
@@ -71,8 +74,8 @@
     if (!status)
     {
         update_now_usec(tv);
-        tv->tv_sec = now;
-        tv->tv_usec = now_usec;
+        tv->tv_sec = (tv_sec_t)now;
+        tv->tv_usec = (tv_usec_t)now_usec;
     }
     return status;
 }
@@ -116,20 +119,21 @@
 
 /* return tv1 - tv2 in usec, constrained by max_seconds */
 static inline int
-tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const unsigned int max_seconds)
+tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const int max_seconds)
 {
     const int max_usec = max_seconds * 1000000;
-    const int sec_diff = tv1->tv_sec - tv2->tv_sec;
+    const tv_sec_t sec_diff = tv1->tv_sec - tv2->tv_sec;
 
-    if (sec_diff > ((int)max_seconds + 10))
+    if (sec_diff > (max_seconds + 10))
     {
         return max_usec;
     }
-    else if (sec_diff < -((int)max_seconds + 10))
+    else if (sec_diff < -(max_seconds + 10))
     {
         return -max_usec;
     }
-    return constrain_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec, max_usec);
+    const time_t complete_diff = sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec);
+    return constrain_int((int)complete_diff, -max_usec, max_usec);
 }
 
 static inline void
@@ -223,8 +227,8 @@
 static inline void
 tv_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2)
 {
-    int sec = t2->tv_sec - t1->tv_sec;
-    int usec = t2->tv_usec - t1->tv_usec;
+    tv_sec_t sec = t2->tv_sec - t1->tv_sec;
+    tv_usec_t usec = t2->tv_usec - t1->tv_usec;
 
     while (usec < 0)
     {
@@ -241,10 +245,6 @@
     dest->tv_usec = usec;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #define TV_WITHIN_SIGMA_MAX_SEC  600
 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie22f4902162b7004542f030c734b968de71e0e9e
Gerrit-Change-Number: 1274
Gerrit-PatchSet: 9
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email )

Change subject: otime: Fix various conversion warnings
......................................................................

otime: Fix various conversion warnings

Generally just use better types. Use typedef
to handle the Win32 situation where tv_sec
is long which is smaller than time_t (which
is long long).

Change-Id Ie22f4902162b7004542f030c734b968de71e0e9e

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34462.html

---
M src/openvpn/otime.c
M src/openvpn/otime.h

2 files changed, 26 insertions(+), 39 deletions(-)
src/openvpn/otime.c +7 -20
index d9bf157..1b3b096 100644
@@ -95,50 +95,37 @@
 const char *
 tv_string_abs(const struct timeval *tv, struct gc_arena *gc)
 {
-    return time_string((time_t)tv->tv_sec, (long)tv->tv_usec, true, gc);
+    return time_string(tv->tv_sec, tv->tv_usec, true, gc);
 }
 
 /* format a time_t as ascii, or use current time if 0 */
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 const char *
-time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)
+time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(64, gc);
     struct timeval tv;
 
-    if (t)
-    {
-        tv.tv_sec = t;
-        tv.tv_usec = usec;
-    }
-    else
+    if (!t)
     {
         gettimeofday(&tv, NULL);
+        t = tv.tv_sec;
+        usec = tv.tv_usec;
     }
 
-    t = tv.tv_sec;
     struct tm *tm = localtime(&t);
 
     buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1,
                tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-    if (show_usec && tv.tv_usec)
+    if (show_usec && usec)
     {
-        buf_printf(&out, " us=%ld", (long)tv.tv_usec);
+        buf_printf(&out, " us=%ld", (long)usec);
     }
 
     return BSTR(&out);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Limit the frequency of an event stream.
  *
src/openvpn/otime.h +19 -19
index 108d0f2..60533fd 100644
@@ -27,6 +27,14 @@
 #include "integer.h"
 #include "buffer.h"
 
+#ifdef _WIN32
+typedef long tv_sec_t;
+typedef long tv_usec_t;
+#else
+typedef time_t tv_sec_t;
+typedef suseconds_t tv_usec_t;
+#endif
+
 struct frequency_limit
 {
     int max;
@@ -42,7 +50,7 @@
 bool frequency_limit_event_allowed(struct frequency_limit *f);
 
 /* format a time_t as ascii, or use current time if 0 */
-const char *time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc);
+const char *time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc);
 
 /* struct timeval functions */
 
@@ -59,11 +67,6 @@
 extern time_t now_usec;
 void update_now_usec(struct timeval *tv);
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 static inline int
 openvpn_gettimeofday(struct timeval *tv, void *tz)
 {
@@ -71,8 +74,8 @@
     if (!status)
     {
         update_now_usec(tv);
-        tv->tv_sec = now;
-        tv->tv_usec = now_usec;
+        tv->tv_sec = (tv_sec_t)now;
+        tv->tv_usec = (tv_usec_t)now_usec;
     }
     return status;
 }
@@ -116,20 +119,21 @@
 
 /* return tv1 - tv2 in usec, constrained by max_seconds */
 static inline int
-tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const unsigned int max_seconds)
+tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const int max_seconds)
 {
     const int max_usec = max_seconds * 1000000;
-    const int sec_diff = tv1->tv_sec - tv2->tv_sec;
+    const tv_sec_t sec_diff = tv1->tv_sec - tv2->tv_sec;
 
-    if (sec_diff > ((int)max_seconds + 10))
+    if (sec_diff > (max_seconds + 10))
     {
         return max_usec;
     }
-    else if (sec_diff < -((int)max_seconds + 10))
+    else if (sec_diff < -(max_seconds + 10))
     {
         return -max_usec;
     }
-    return constrain_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec, max_usec);
+    const time_t complete_diff = sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec);
+    return constrain_int((int)complete_diff, -max_usec, max_usec);
 }
 
 static inline void
@@ -223,8 +227,8 @@
 static inline void
 tv_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2)
 {
-    int sec = t2->tv_sec - t1->tv_sec;
-    int usec = t2->tv_usec - t1->tv_usec;
+    tv_sec_t sec = t2->tv_sec - t1->tv_sec;
+    tv_usec_t usec = t2->tv_usec - t1->tv_usec;
 
     while (usec < 0)
     {
@@ -241,10 +245,6 @@
     dest->tv_usec = usec;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #define TV_WITHIN_SIGMA_MAX_SEC  600
 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1274?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie22f4902162b7004542f030c734b968de71e0e9e
Gerrit-Change-Number: 1274
Gerrit-PatchSet: 9
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>